ZF.add('dom-offset', function(Z) {

    var D = Z.Dom,
        S = Z.String,
        win = window,
        doc = document,
        isIOS = Z.Browser.Platform.ios,
        isStrict = doc.compatMode === 'CSS1Compat',
        DOCUMENT_ELEMENT = 'documentElement',
        BODY = 'body',
        SCROLL = 'scroll',
        INNER = 'inner',
        CLIENT = 'client',
        VIEWPOINT = 'viewport',

        HEIGHT_U = 'Height',
        WIDTH_U = 'Width',
        LEFT_U = 'Left',
        TOP_U = 'Top',
        
        GET_BOUNDING_CLIENT_RECT = 'getBoundingClientRect';

    Z.extend(D, {

        offset : function(item) {
            var x = 0, y = 0, rect;
            
            if (item[GET_BOUNDING_CLIENT_RECT]) {
                rect = item[GET_BOUNDING_CLIENT_RECT]();

//                x = rect.left;
                y = rect.top;

                if (!isIOS) {
 //                   x += D.scrollLeft();
                    y += D.scrollTop();
                }
            }

            return { x : x, y : y };
        },
        
        scroll : function() {
            return { x : D[SCROLL + LEFT_U](), y : D[SCROLL + TOP_U]() };
        },
        
        viewport : function() {
            return { x : D[VIEWPOINT + WIDTH_U](), y : D[VIEWPOINT + HEIGHT_U]() };
        }

    });

    // scrollLeft/scrollTop
    Z.each([LEFT_U, TOP_U], function(r, i) {
        D[SCROLL + r] = function() {
            return win['page' + (i ? 'Y' : 'X') + 'Offset'] || doc[DOCUMENT_ELEMENT][SCROLL + r] || doc[BODY][SCROLL + r];
        };
    });

    // viewportWidth/viewportHeight
    Z.each([WIDTH_U, HEIGHT_U], function(r) {
        D[VIEWPOINT + r] = function() {
            return win && win[INNER + r] ? win[INNER + r] : (isStrict ? doc[DOCUMENT_ELEMENT][CLIENT + r] : doc[BODY][CLIENT + r]);
        };
    });

}, { requires : ['dom'] });
